#ifndef __DFA_H__
#define __DFA_H__

#include <map>
#include <fstream>
#include <string>

class DFA {
	struct Range {
		Range(const std::string start, const std::string end);
		std::string start;
		std::string end;

		bool operator< (const Range &other) const;

		static std::string UnescapeWhitespace(const std::string);
	};
	struct State {
		//Gives us access to the members, without exposing them as public members
		friend class DFA;
		std::map<Range, std::string> transitions;
		const std::string *name;
		bool isAccepting;
		std::string defaultState;

		State() {}
		State(const std::string &accepting);

		bool TransitionOn(DFA *dfa, std::string s);
	};

	//Abstraction to remove all characters in a stream up to the next carriage return
	static void RemoveRestOfLine(std::ifstream &);
	static bool GetString(std::ifstream &, std::string &);

	std::map<std::string, State> _states;
	State *_startState;
	State *_currentState;
	bool _startOver;
public:
	DFA(const char *filename);

	void Reset();
	bool TransitionOn(const std::string s);
	std::string CurrentStateName();
};

#endif